/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.ucase.casemain.controller;

import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseTemporaryRecordQueryDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseTemporarySaveDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseTemporaryRecord;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseTemporaryRecordService;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 描述: 文书内容暂存表 case_temporary_record 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年03月24日
 */
@RequestMapping("/punish/ucase/temporary")
@RestController
public class CaseTemporaryRecordController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseTemporaryRecordController.class);

    @Resource
    private ICaseTemporaryRecordService caseTemporaryRecordService;

    /**
     * 文书暂存功能--通用
     * @author : lxj
     * @param saveDto
     * @return
     */
    @RequestMapping ("/saveTemporary")
    public Result saveCaseReasonRecord(@RequestBody CaseTemporarySaveDto saveDto) {
        boolean success = caseTemporaryRecordService.saveTemporary(saveDto);
        if(success){
            return Result.success("success");
        }
        return Result.error("失败");
    }


    /**
     * 获取文书暂存记录
     *
     * @author: zhengqiang
     * @date: 2022/5/16
     * @param: caseTemporaryRecordQueryDto
     * @return {@link Result< JSONObject>}
     **/
    @RequestMapping(value = "/getDocTemporaryRecord")
    public Result<JSONObject> getDocTemporaryRecord(@RequestBody @Validated CaseTemporaryRecordQueryDto caseTemporaryRecordQueryDto) {
        CaseTemporaryRecord record = caseTemporaryRecordService.getRecord(caseTemporaryRecordQueryDto);
        if(record==null){
            return Result.success(Constant.STRING_NOT_FOUND);
        }
        JSONObject jsonObject = JSONObject.parseObject(record.getContent());
        return Result.success(jsonObject);
    }


}
